import math
import numpy as np
import matplotlib.pyplot as plt
n = 8
Il = []
Ir = []
def fx(x):
    return math.exp(x)
def xl_ractangle(start_num,stop_num,n):
    #```Left```
    dx = (stop_num- start_num)/(n+1)
    xl = []
    for i in range(n):
        xl.append(start_num+i*dx)
    sumfx = 0.00
    for xp in xl:
        fxv = fx(xp)
        sumfx = sumfx + fxv
    print(sumfx*dx)
    return sumfx*dx

def xr_ractangle(start_num,stop_num,n):
    #````Right````
    dx = (stop_num- start_num)/(n+1)
    xl = []
    for i in range(n):
        xl.append(start_num+(i+1)*dx)
    sumfx = 0.00
    for xp in xl:
        fxv = fx(xp)
        sumfx = sumfx + fxv
    return sumfx*dx
for k in range(1,n+1,1):
    il = xl_ractangle(0,math.pi,k)
    ir = xr_ractangle(0,math.pi,k)
    Il.append(il)
    Ir.append(ir)
Ix = range(1,n+1,1)
line1 = plt.plot(Ix,Il,label = "Left Rectangle",linewidth = "1", color = "black", linestyle = "--")
line2 = plt.plot(Ix,Ir,label = "Right Rectangle",linewidth = "1", color = "red", linestyle = "-")
plt.xlabel("Older")
plt.ylabel("Value")
plt.title("Compound integrals")
plt.legend()
plt.show()
